import Config from '@/config/index.js'
import utils from '@/utils/index.js'
import {
  formatDate,
} from '@/utils/date.js'
const appMethods = {
  loading: (title = '', mask = true) => uni.showLoading({
    title,
    mask,
  }),
  loaded: () => uni.hideLoading(),

  alert: (title, content) => uni.showModal({
    title,
    content,
    showCancel: false,
  }),

  confirm: (title, content, confirmColor = '#ff9047') => uni.showModal({
    title,
    content,
    confirmColor,
  }),

  msg: (title, duration = 1000, icon = 'none') => uni.showToast({
    title,
    duration,
    icon,
  }),

  navigateTo: (options) => {
    options.url = utils.mergeURL(options.url, options.data)
    return uni.navigateTo(options)
  },

  formatDate,
}
const install = (Vue) => {
  Vue.prototype.$config = Config

  // 2. 添加全局方法
  Object.keys(appMethods).forEach((v) => {
    Vue.prototype[`$${v}`] = appMethods[v]
  })
}

export default {
  install,
}
